package com.lili.order.service.impl.payment;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.order.entity.PageMap;
import com.lili.model.order.entity.payment.Refund;
import com.lili.order.mapper.payment.RefundMapper;
import com.lili.order.service.payment.RefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;

@Service
public class RefundServiceImpl implements RefundService {
    @Autowired
    RefundMapper refundMapper;

    public int delete(Serializable id) {
        return refundMapper.myDeleteById(id);
    }
    public  int save(Refund refund){
        return refundMapper.insert(refund);
    }
    public  int update(Refund refund){
        QueryWrapper<Refund> wrapper=new QueryWrapper<>();
        wrapper.eq("id",refund.getId());
        return refundMapper.update(refund,wrapper);
    }
    public Page<Refund> queryByPage(Map map){
        QueryWrapper<Refund> wrapper=new QueryWrapper<>();
        PageMap pageMap=new PageMap(map);
        if(map.containsKey("orderSn")){
            wrapper.eq("order_sn",map.get("orderSn"));
        }
        if(map.containsKey("isRefund")){
            wrapper.eq("is_refund",map.get("isRefund"));
        }
        if(map.containsKey("beginTime")&&map.containsKey("endTime")){
            wrapper.between("create_time",map.get("beginTime"),map.get("endTime"));
        }
        if(map.containsKey("storeId")){
            wrapper.like("store_id",map.get("storeId"));
        }
        Page<Refund> page=new Page<>(pageMap.getPage(),pageMap.getPageSize());
        refundMapper.selectPage(page,wrapper);
         return  page;
    }

}
